#pragma once
#ifndef GRAPHIC_PLUGIN_IMPL_INCLUDED
#define GRAPHIC_PLUGIN_IMPL_INCLUDED

#include "shared\typedefs.h"
#include "boost\cstdint.hpp"
#include <string>
#include <map>
#include "shared\struct_extraction.h"
#include <lib\shared_lib\pugixml.hpp>
//#include <lib\rle_lib\ProductionJobData.h>

using namespace boost;

class UtfConverter;
class ProductionJobData;
class CBitmapExData;
struct ExtractionAreas;
struct ExtractionObject;

namespace pugi {
	class xml_node;
};


class GraphicPluginImpl
{
private:
	struct _PlaneInfo {
		int             BitsPerColor;
		int             BitsPerPlanePixel;
		std::string     strColorOrder;
		std::string     strChannelOrder;
		int             Width;
		int             Height;
		std::string     strDefaultOrientation;
		std::string     strFlipAxis;
		bool            FlipHorizontal;
		bool            FlipVertical;
		bool            InvertColors;
		std::string     strDrawingPlane;
		boost::uint32_t BackgroundColor; // must be 24-bit color
	};

	struct _GpJobData {
		ProductionJobData *pPjd;
//		std::string strBitmapFile[ ProductionJobData::SIDES_TOTAL ];
		bool BitmapLoaded[ ProductionJobData::SIDES_TOTAL ];
	};
	typedef std::map<jobid_t, _GpJobData> JobMap_t;
	JobMap_t JobMap_;

	std::map<std::string,_PlaneInfo> PlaneInfoMap_;

	boost::shared_ptr<UtfConverter> pUtfConverter_;

	void convertPlaneInfoToNode( IN const _PlaneInfo &pi, OUT pugi::xml_node Node );
	void initPlaneInfo();
	void addUvBitmap( INOUT ExtractionAreas_t &AllAreas, IN const char *pszBitmapFile );
	bool processPre( IN jobid_t ProductionJobId,
					 IN pugi::xml_document &DocArea,
					 IN ExtractionObject &Object,
					 INOUT CBitmapExData &DstBmpData,
					 OUT std::string &strResult );
/*
	bool processPost( IN jobid_t ProductionJobId,
					  IN pugi::xml_document &DocArea,
					  IN ExtractionObject &Object,
					  INOUT CBitmapExData &DstBmpData );
*/
	void GraphicPluginImpl::limitAreas( INOUT ExtractionAreas &AllAreas );


public:
	GraphicPluginImpl(void);
	~GraphicPluginImpl(void);

	result initGraphicPlugin(
		IN const char *pszInput,
		OUT std::string &strPluginInfo );

	result queryPlaneInfo(
		IN const char *pszPlane,
		OUT std::string &strPlaneInfo );

	result GraphicPluginImpl::startPage( 
		IN jobid_t ProductionJobId, 
		IN ProductionJobData &pjd,
		IN const char *pszPlane,
		INOUT CBitmapExData &PlaneBitmap );

	result processArea(
		IN jobid_t ProductionJobId, 
		IN ExtractionObject &Object,
		IN const char *pszArea,
		INOUT CBitmapExData &PlaneBitmap,
		OUT std::string &strResult
	);

	result endDocument( IN jobid_t ProductionJobId );

	result preprocessAreas(
		IN jobid_t ProductionJobId,
		IN const char *pszPlane,
		IN const char *pszProfile,
		INOUT ExtractionAreas &AllAreas );
};

#endif // GRAPHIC_PLUGIN_IMPL_INCLUDED
